package com.petdog.common.dto;

import com.petdog.common.constant.ResponseCode;
import lombok.Data;

import java.io.Serializable;

/**
 * API响应数据封装类
 */
@Data
public class ResponseDTO<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    
    // 是否成功
    private boolean success;
    
    // 状态码
    private int code;
    
    // 数据
    private T data;
    
    // 消息
    private String message;
    
    // 错误信息（可选）
    private String error;
    
    /**
     * 成功响应
     */
    public static <T> ResponseDTO<T> success(T data, String message) {
        ResponseDTO<T> response = new ResponseDTO<>();
        response.setSuccess(true);
        response.setCode(ResponseCode.SUCCESS);
        response.setData(data);
        response.setMessage(message);
        return response;
    }
    
    /**
     * 失败响应
     */
    public static <T> ResponseDTO<T> fail(int code, String message) {
        ResponseDTO<T> response = new ResponseDTO<>();
        response.setSuccess(false);
        response.setCode(code);
        response.setMessage(message);
        response.setError(message);
        return response;
    }
    
    /**
     * 失败响应（带错误详情）
     */
    public static <T> ResponseDTO<T> fail(int code, String message, String error) {
        ResponseDTO<T> response = new ResponseDTO<>();
        response.setSuccess(false);
        response.setCode(code);
        response.setMessage(message);
        response.setError(error);
        return response;
    }
}